import os
from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

class Config:
    """配置类，从环境变量中读取配置"""
    
    # Kafka配置
    KAFKA_BOOTSTRAP_SERVERS = os.getenv('KAFKA_BOOTSTRAP_SERVERS', 'localhost:9092')
    KAFKA_TOPIC = os.getenv('KAFKA_TOPIC', 'web-monitor')
    KAFKA_GROUP_ID = os.getenv('KAFKA_GROUP_ID', 'web-monitor-group')
    
    # OSS存储配置
    OSS_ENDPOINT = os.getenv('OSS_ENDPOINT', '')
    OSS_ACCESS_KEY_ID = os.getenv('OSS_ACCESS_KEY_ID', '')
    OSS_ACCESS_KEY_SECRET = os.getenv('OSS_ACCESS_KEY_SECRET', '')
    OSS_BUCKET_NAME = os.getenv('OSS_BUCKET_NAME', '')
    
    # 数据库配置
    DATABASE_URL = os.getenv('DATABASE_URL', 'sqlite:///./webmonitor.db')
    
    # PostgreSQL数据库配置
    POSTGRES_HOST = os.getenv('POSTGRES_HOST', 'localhost')
    POSTGRES_PORT = os.getenv('POSTGRES_PORT', '5433')
    POSTGRES_USER = os.getenv('POSTGRES_USER', 'postgres')
    POSTGRES_PASSWORD = os.getenv('POSTGRES_PASSWORD', 'mkmR@L55Y@6c#G@')
    POSTGRES_DB = os.getenv('POSTGRES_DB', 'demo_db')
    
    # 日志配置
    LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
    ENABLE_LOGGING = os.getenv('ENABLE_LOGGING', 'True').lower() == 'true'
    
    # 其他配置
    MAX_MESSAGE_LENGTH = int(os.getenv('MAX_MESSAGE_LENGTH', '1000'))
    
    # API配置
    API_PORT = int(os.getenv('API_PORT', '8000'))
    API_HOST = os.getenv('API_HOST', '0.0.0.0')

# 创建配置实例
config = Config()